#! /usr/bin/python3
# -*- coding: UTF-8 -*-
import requests
import time
header = {"User-Agent": "Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)"}  # 新增百度蜘蛛头
# r1 = requests.get('https://www.zygd.site', timeout=10, headers=header)


def site_test(timeout):
    r1 = requests.get(i, timeout=timeout, headers=header, verify=True)  #
    print(r1.url, r1.reason, r1.elapsed, r1.status_code, r1.encoding, r1.headers['Server'])  # 最终地址   响应状态描述请求时间 请求状态值 自动编码检测


with open("sites.txt", 'r') as sites:
    for i in sites.readlines():
        try:
            site_test(1)
        except IOError:
            try:
                site_test(5)
            except IOError:
                try:
                    print(i, ' 站点异常正在重试...')
                    site_test(10)
                except IOError:
                    times = time.strftime("%m-%d-%H:%M:%S", time.localtime())
                    with open("log.txt", 'a', encoding="UTF-8") as log:
                        log.write(times + '  ' + i + '   ' + "访问异常\n")
                        print(i, '  访问异常', '    请查看日志文件！')

